﻿using System;
using System.ComponentModel;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace WpfAdvControls.WpfConverters
{
    [ValueConversion(typeof (double), typeof (Thickness))]
    public class DoubleThicknessConverter : IValueConverter
    {
        [DefaultValue(5)]
        public double Top { get; set; }

        [DefaultValue(5)]
        public double Left { get; set; }

        [DefaultValue(5)]
        public double Bottom { get; set; }

        [DefaultValue(5)]
        public double Right { get; set; }

        [DefaultValue(20)]
        public double Multiplier { get; set; }

        #region IValueConverter Members

        public object Convert(object value, Type targetType,
            object parameter, CultureInfo culture)
        {
            var val = (int) value*Multiplier;
            switch ((string) parameter)
            {
                case "Left":
                    Left = val;
                    break;
                case "Top":
                    Top = val;
                    break;
                case "Bottom":
                    Bottom = val;
                    break;
                case "Right":
                    Right = val;
                    break;
            }
            return new Thickness(Left, Top, Right, Bottom);
        }

        public object ConvertBack(object value, Type targetType,
            object parameter, CultureInfo culture)
        {
            return 0;
        }

        #endregion
    }
}